package cn.myjerry.net.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * 服务端
 * 1、创建服务 + 端口
 * 2、准备接收容器
 * 3、封装成包
 * 4、接收数据
 * 5、分析数据
 * 6、释放资源
 * @author Jerry
 *
 */
public class MyServer {
	public static void main(String[] args) throws IOException {
		DatagramSocket server = new DatagramSocket(8888);
		
		byte[] conatiner = new byte[1024];
		
		DatagramPacket packet = new DatagramPacket(conatiner, conatiner.length);
		
		server.receive(packet);
		
		byte[] data = packet.getData();
		int len = packet.getLength();
		
		System.out.println(new String(data, 0, len));
		
		server.close();
	}
}
